package cn.honglian.system.controller;

import cn.honglian.basic.util.AjaxResult;
import cn.honglian.basic.util.PageList;
import cn.honglian.system.domain.Systemdictionarydetail;
import cn.honglian.system.query.SystemdictionarydetailQuery;
import cn.honglian.system.service.SystemdictionarydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tail")
public class SystemdictionarydetailController {

    @Autowired
    private SystemdictionarydetailService systemdictionarydetailService;

    @PostMapping()
    public PageList queryBypage(@RequestBody SystemdictionarydetailQuery systemdictionarydetailQuery){

        return systemdictionarydetailService.queryByPage(systemdictionarydetailQuery);
    }
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            systemdictionarydetailService.delete(id);
        } catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().fail();
        }
        return AjaxResult.me().success();
    }

    @PatchMapping()
    public AjaxResult batchDelete(@RequestBody List<Long> ids){

        try {
            systemdictionarydetailService.batchDelete(ids);
        } catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().fail();
        }
        return AjaxResult.me().success();
    }


    @PutMapping()
    public AjaxResult addAndUpdate(@RequestBody Systemdictionarydetail systemdictionarydetail){

        try {
           if (null!= systemdictionarydetail.getId()){
               systemdictionarydetailService.update(systemdictionarydetail);
           }else {
               systemdictionarydetailService.add(systemdictionarydetail);
           }

        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().fail();
        }
        return AjaxResult.me().success();
    }

    @GetMapping("/{id}")
    public List<Systemdictionarydetail> findByIds(@PathVariable Long id){
        List<Systemdictionarydetail> byIds = systemdictionarydetailService.findByIds(id);
        return  byIds;
    }

}
